package com.xr.redis.util;

import java.util.concurrent.*;

/**
 * @author Arnold Yand
 * @summary 线程池工具类
 */
public class ThreadPoolUtil {

  protected static int MAX_FIXED_THREAD_SIZE = 5;

  private ThreadPoolUtil() {
  }

  public static void submit(Runnable task) {
    getThreadPoolInstance().submit(task);
  }

  public static Future submit(Callable task) {
    return getThreadPoolInstance().submit(task);
  }

  private static ExecutorService getThreadPoolInstance() {
    return LocalThreadPool.executorService;
  }

  private static class LocalThreadPool {
    // corePoolSize:10 maximumPoolSize:3000 keepAliveTime:60s workQueue:任务等待队列长度
    private static ExecutorService executorService = new ThreadPoolExecutor(10, 3000, 60L, TimeUnit.SECONDS,new LinkedBlockingQueue<Runnable>(5000));
  }
}
